package com.myproject.mall.goods.controller;

import com.myproject.mall.common.result.HttpResult;
import com.myproject.mall.domain.dto.GoodsDTO;
import com.myproject.mall.domain.entity.Goods;
import com.myproject.mall.goods.service.IGoodsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "商品接口")
@RestController
@RequestMapping("/api/goods")
@RequiredArgsConstructor
public class GoodsController {
    private final IGoodsService goodsService;

    @Operation(summary = "获取某商店商品")
    @GetMapping("/get/{shopId}")
    public HttpResult<Void> getShopGoods() {
//        TODO 分页查询
        return HttpResult.success();
    }

    @Operation(summary = "获取商品详情")
    @GetMapping("/get/detail/{goodsId}")
    public HttpResult<GoodsDTO> getGoodsDetail(@PathVariable("goodsId") Long goodsId) {
        return HttpResult.success(goodsService.getGoodsDetail(goodsId));
    }

    @Operation(summary = "添加商品")
    @PostMapping("/seller/add/{shopId}")
    public HttpResult<Long> addGoods(@PathVariable("shopId") Long shopId, @RequestBody Goods goods) {
        return HttpResult.success(goodsService.addGoods(shopId, goods));
    }

    @Operation(summary = "下架商品")
    @GetMapping("/seller/offline/{goodsId}")
    public HttpResult<String> offlineGoods(@PathVariable("goodsId") Long goodsId) {
        goodsService.offlineGoods(goodsId);
        return HttpResult.success("success");
    }

    @Operation(summary = "更新商品")
    @PostMapping("/seller/update")
    public HttpResult<String> updateGoods(@RequestBody Goods goods) {
        goodsService.updateGoods(goods);
        return null;
    }

}
